<?php
if (COUNT($_POST))
{
	$key = $this->get('key');
    Connection::getConnect();
	if (is_numeric($key))
	{
		$sql = "SELECT id.iid, id.name, ii.quantity, ii.barcode, ii.retail_price, ii.whole_sale_price, si.item_unit, iu.name, si.per_unit, ii.reorder FROM item_details id JOIN item_inventory ii USING(iid) JOIN supplier_item_cost si USING(iid) JOIN item_unit_detail iu USING(imdid) WHERE ii.barcode='$key' GROUP BY id.name";
    	Connection::setQuery($sql);
    	$result = Connection::fetch();
		if (COUNT($result) == 1){
        	$sql = "SELECT id.iid, id.name, ii.quantity, ii.barcode, ii.retail_price, ii.whole_sale_price, si.item_unit, iu.name, si.per_unit, ii.reorder FROM item_details id JOIN item_inventory ii USING(iid) JOIN supplier_item_cost si USING(iid) JOIN item_unit_detail iu USING(imdid) WHERE id.iid='$key' GROUP BY id.name";
            Connection::setQuery($sql);
            $result = Connection::fetch();
		}
	}
	else
	{
    	$sql = "SELECT id.iid, id.name, ii.quantity, ii.barcode, ii.retail_price, ii.whole_sale_price, si.item_unit, iu.name, si.per_unit, ii.reorder FROM item_details id JOIN item_inventory ii USING(iid) JOIN supplier_item_cost si USING(iid) JOIN item_unit_detail iu USING(imdid) WHERE id.name='$key' GROUP BY id.name";
        Connection::setQuery($sql);
        $result = Connection::fetch();
	}
}
?>